package com.dongdongshop.controller;

import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONObject;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.util.HttpClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @ClassName SSSS
 * @Author RC
 * @date 2021.01.07 16:19
 */
@Controller
@RequestMapping("nationalEpidemic")
public class NationalEpidemicController {
 public static final Logger logger = LoggerFactory.getLogger(NationalEpidemicController.class);

    @RequestMapping("getNationalEpidemic")
    @ResponseBody
    public Map<String,Object> getWeather(HttpServletRequest request) {

            logger.info("查询全国疫情趋势");
            //使用httpclient 调用接口获取数据
            String s = HttpClientUtil.doGet("https://interface.sina.cn/news/wap/fymap2020_data.d.json");
            Map map = (Map) JSONObject.parseObject(s).get("data");
            List otherlist = (List) map.get("otherlist");
            Map<String,Object> map1 = new HashMap<>();
            map1.put("data",otherlist);
            return map1;

    }
    public static void main(String[] args) {

        String s = HttpClientUtil.doGet("https://interface.sina.cn/news/wap/fymap2020_data.d.json");
        Map<String,Object>  map =(Map<String,Object> ) JSON.parse(s);
        System.out.println(map);

    }

}
